<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

define("MSG_SUCCESS", "Données sauvegarder avec succès.");
define("MSG_ERROR", "Les données ont été effacer avec succès.");
define("MSG_DELETE_SUCCESS", "Logo éliminé avec succès.");

class PartenairesController extends JLControllerBase {

    private $config = null;
    private $path = "Partenaires";
    private $title = "Système d'Actualisation CSME > Partenaires";
    private $data = null;

    public function Index() {
        $data['title'] = $this->title;
        $data['texttitle'] = " > " . $this->path;
        $data['classcurrent8'] = ' class="current"';

        require JLPATH_MODELS . DS . "StateModel.php";
        $states = new StateModel();
        $data['states'] = $states->getStates();

        $this->View->Show($this->path, $this->title, $data);
    }

    function addPartenaires() {
        if ($this->isSetNoEmpty($_POST['time'])) {
            require JLPATH_MODELS . DS . "PartenairesModel.php";
            $part = new PartenairesModel();
            $count = $part->countPartenaires();
            $count++;
            $b = $part->insert($count, 2);
            echo ($b) ? MSG_SUCCESS : MSG_ERROR;
        }
    }

    function getPartenaires() {
        require JLPATH_MODELS . DS . "PartenairesModel.php";
        $part = new PartenairesModel();
        $parts = $part->getPartenaires();

        echo json_encode($parts);
    }

    function getLogosByPart() {
        $id_int_partenaire = $_POST['cboplanches'];

        require JLPATH_MODELS . DS . "LogosModel.php";
        $logo = new LogosModel();
        $logos = $logo->getLogosByIdPart($id_int_partenaire);
        echo json_encode($logos);
    }

    function removePartenaires() {
        if ($this->isSetNoEmpty($_POST['id'])) {
            $id = $_POST['id'];
            require JLPATH_MODELS . DS . "PartenairesModel.php";
            $part = new PartenairesModel();

            $b = $part->delete($id);
            echo ($b) ? MSG_SUCCESS : MSG_ERROR;
        }
    }

}